﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;

using Script.Net.Scripts;
using System.Web;


namespace Script.Net.WebForms
{
	public class ScriptBlock : Control, ITextControl
	{

		public string Alias
		{
			get { return (string)ViewState["Alias"]; }
			set { ViewState["Alias"] = value; }
		}

		public string Dependencies
		{
			get { return (string)ViewState["Dependencies"]; }
			set { ViewState["Dependencies"] = value; }
		}

		[
		PersistenceMode(PersistenceMode.InnerDefaultProperty),
		DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
		]
		public string Text
		{
			get { return (string)ViewState["Text"]; }
			set { ViewState["Text"] = value; }
		}



		protected override void OnPreRender(EventArgs e)
		{
			base.OnPreRender(e);

			ScriptFactory.Repository.CreateScript(new ScriptContent
			{
				Alias = Alias,
				Dependencies = (string.IsNullOrEmpty(this.Dependencies) ? this.Dependencies.Split(',') : null),
				Content = new HtmlString(this.Text)
			});
		}

		protected override void Render(HtmlTextWriter writer)
		{
 			 //Do nothing
		}


	}
}
